<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.1</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" href="__ADMIN__/css/font.css">
    <link rel="stylesheet" href="__ADMIN__/css/xadmin.css">
    <script type="text/javascript" src="__ADMIN__/js/jquery.min.js"></script>
    <script type="text/javascript" src="__ADMIN__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ADMIN__/js/xadmin.js"></script>
    <script type="text/javascript" src="__ADMIN__/js/cookie.js"></script>
    <link rel="stylesheet" href="/static/admin/css/font.css">
    <link rel="stylesheet" href="/static/admin/css/font-awesome.min.css">
    <style>
        .layui-form-item .layui-form-label{
            width: 120px;
        }
        .layui-form-item .layui-textarea{
            width: 190px;
        }
        #phone-one-div {display: none}
    </style>
  </head>
  
  <body>
    <div class="x-body">
        <form class="layui-form">
          <div class="layui-form-item">
              <label for="goods_id" class="layui-form-label">
                  <span class="x-red">*</span>选择礼品
              </label>
              <div class="layui-input-inline">
                    <select name="goods_id" lay-search lay-verify="required" required lay-filter="filter">
                        <option value="">请选择</option>
                        {volist name="goodsList" id="value"}
                        <option value="{$value.id}" stock="{$value.stock}">[{$value.brand}]{$value.goods_name}</option>
                        {/volist}
                    </select>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="stock" class="layui-form-label">
                  库存
              </label>
              <div class="layui-input-inline">
                  <input type="number" value="0" id="stock" name="stock" readonly autocomplete="off" class="layui-input">
              </div>
          </div>
          <!--<div class="layui-form-item">-->
          <!--    <label for="client_id" class="layui-form-label">-->
          <!--        <span class="x-red">*</span>选择活动-->
          <!--    </label>-->
          <!--    <div class="layui-input-inline">-->
          <!--          <select name="client_id" lay-search lay-verify="required" required>-->
          <!--              <option value="">请选择</option>-->
          <!--              <option value="0">其他</option>-->
          <!--              {volist name="clientList" id="value"}-->
          <!--              <option value="{$value.id}">{$value.id}-{$value.activity}</option>-->
          <!--              {/volist}-->
          <!--          </select>-->
          <!--    </div>-->
          <!--</div>-->
          <div class="layui-form-item">
              <label for="count" class="layui-form-label">
                  <span class="x-red">*</span>直播平台id
              </label>
              <div class="layui-input-inline">
                  <input type="number" value="{$value.live_id}" min="0" lay-verify="required" required id="live_id" name="live_id" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="activity_name" class="layui-form-label">
                  <span class="x-red">*</span>活动名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" value="{$value.activity_name}" readonly id="activity_name" name="activity_name" lay-verify="required" required="" autocomplete="off" class="layui-input" style="background:#eee" placeholder="请填写直播平台id获取">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="count" class="layui-form-label">
                  <span class="x-red">*</span>申请数量
              </label>
              <div class="layui-input-inline">
                  <input type="number" value="1" min="0" lay-verify="required" required id="count" name="count" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="consignee" class="layui-form-label">
                  <span class="x-red">*</span>收件人姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" value=""  lay-verify="required" required id="consignee" name="consignee" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="phone" class="layui-form-label">
                  <span class="x-red">*</span>收件人电话
              </label>
              <div class="layui-input-inline">
                  <input type="text" value="" lay-verify="required" required id="phone" name="phone" autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="address" class="layui-form-label">
                  <span class="x-red">*</span>收件人地址
              </label>
              <div class="layui-input-inline">
                  <input type="text" value="" lay-verify="required" required id="address" name="address" autocomplete="off" class="layui-input">
              </div>
          </div>
          
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button type="button" class="layui-btn" lay-filter="add" lay-submit="">
                  确定
              </button>
          </div>
      </form>
    </div>

    <script>
        layui.use(['form','layer','laydate','upload'], function(){
          $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer
          ,laydate = layui.laydate
          ,upload = layui.upload;

            form.on('select(filter)', function(data){
              if(data.value){
                  $.get('{:url('ds/getStockById')}/id/'+data.value,function(d){
                      $('#stock').val(d.stock);
                      //$('#count').attr('max',d.stock);
                      $('#count').attr('oninput','if(value>'+d.stock+')value='+d.stock+';if(value.length>2)value=value.slice(0,2);if(value<0)value=0')
                      if(d.stock == 0){
                          layer.alert('对不起，库存不足，请联系管理员补货');
                          $('button').hide();
                      }else{
                          $('button').show();
                      }
                      
                  })
              }
              
            });   
            $('#live_id').blur(function(){
                $.get('/admin.php/Performance/getTotalIncome?live_id='+$(this).val(),function(data){
                    if(data.code == 1)
                    {
                        $('#activity_name').val(data.data.title);
                    }
                },'json')
            })
          //监听提交
          form.on('submit(add)', function(data){
            if(data.field.count <= 0)
                return;
            
            $.ajax({
                type:'POST',
                dataType:'json',
                data:{data:data.field},
                success:function(obj){
                      layer.alert(obj.msg, {icon: obj.icon},function(){
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                        // 可以对父窗口进行刷新 
                        x_admin_father_reload();
                      });    
                }
            });
            return false;
          });
          
          
        });
    </script>
  </body>

</html>